package com.health.controller.manage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.common.PageBean;
import com.health.common.QueryParam;
import com.health.common.R;
import com.health.pojo.Member;
import com.health.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Api(tags = "会员模块")
@RequestMapping("/api/manage/member")
@Slf4j
public class MemberController {

    private final MemberService memberService;

    @ApiOperation(value = "分页查询会员信息")
    @GetMapping("/pageQuery")
    public R pageQuery(QueryParam param) {
        log.info("分页查询会员信息 {}", param);
        log.info("分页条件查询 {}", param);
        Page<Member> page = new Page<>(param.getCurrentPage(), param.getPageSize());
        memberService.query()
                .like(param.getQueryString() != null, "name", param.getQueryString())
                .or()
                .like(param.getQueryString() != null, "telephone", param.getQueryString())
                .page(page);
        PageBean pageBean = new PageBean(page.getRecords(), page.getTotal());
        return R.success(pageBean);
    }
}
